﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;
using System.Data.OleDb;
using System.Collections;
public partial class admin_SiteMap : System.Web.UI.Page
{
    int s = 10;
    protected void Page_Load(object sender, EventArgs e)
    {
        SetXMLMap();
        SetHtmlMap();

    }
    private void SetHtmlMap()
    {
        string str = ProListhtml() + NewsListhtml();
        Hashtable canshu = new Hashtable();
        canshu.Add("$shuliang", s.ToString());
        canshu.Add("$time", DateTime.Now.ToString());
        canshu.Add("$LISTCONN", str);
        if (SetToHtml.ToHtml("Temp-sitemap.html", "sitemap.html", canshu))
        {
            Response.Write("<br/>SiteMap.html生成完成，<a href='../SiteMap.html'>SiteMap.html</a>");
        }
 
    }
    private void SetXMLMap()
    {
        XmlDocument xmldoc = new XmlDocument(); //创建空的XML文档 
        xmldoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
            "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">" +
            "<url> <loc>http://www.fuhepo.cn/</loc> </url>" +
            "<url> <loc>http://www.fuhepo.cn/Products.aspx</loc> </url>" +
            "<url> <loc>http://www.fuhepo.cn/NewsList.aspx</loc> </url>" +
            "<url> <loc>http://www.fuhepo.cn/about/?AID=1</loc> </url>" +
            "<url> <loc>http://www.fuhepo.cn/about/?AID=2</loc> </url>" +
            "<url> <loc>http://www.fuhepo.cn/about/?AID=3</loc> </url>" +
            "<url> <loc>http://www.fuhepo.cn/about/?AID=4</loc> </url>" +
            "<url> <loc>http://www.fuhepo.cn/about/?AID=5</loc> </url>" +
            "<url> <loc>http://www.fuhepo.cn/about/?AID=6</loc> </url>" +

            ProList() +
            NewsList() +
             "</urlset>");
        xmldoc.Save(Server.MapPath("~/SiteMap.Xml")); //保存 
        Response.Write("<br/>SiteMap.Xml生成完成，<a href='../SiteMap.Xml'>SiteMap.Xml</a>");


    }
    private string ProList()
    {
        string str = "";
        OleDbDataReader dr = WebSet.GetDataReadeForSql("Select HtmlUrl,Ptitle from [Product] Order By Pid ASC ");
        while (dr.Read())
        {
            str += "<url>" +
                "<loc>http://www.fuhepo.cn/" + dr["HtmlUrl"].ToString() + "</loc> " +
                "</url>";
        }
        dr.Close();
        return str;
    }
    private string NewsList()
    {
        string str = "";
        OleDbDataReader dr = WebSet.GetDataReadeForSql("Select Htmlurl,Ntitle from [News] Order By NID ASC ");
        while (dr.Read())
        {
            str += "<url>" +
                "<loc>http://www.fuhepo.cn/" + dr["Htmlurl"].ToString() + "</loc> " +
                "</url>";
        }
        dr.Close();
        return str;
    }
    private string ProListhtml()
    {
        string str = "";
        OleDbDataReader dr = WebSet.GetDataReadeForSql("Select HtmlUrl,Ptitle from [Product] Order By Pid ASC ");
        while (dr.Read())
        {
            s++;
            str += "<tr>" +
                "<td class=\"lpage\"><a href=\"http://www.fuhepo.cn/" + dr["HtmlUrl"].ToString() + "\" title=\"" + dr["Ptitle"].ToString() + "\">" + dr["Ptitle"].ToString() + "</a></td>" +
                "</tr>";
        }
        dr.Close();
        return str;
    }
    private string NewsListhtml()
    {
        string str = "";
        OleDbDataReader dr = WebSet.GetDataReadeForSql("Select Htmlurl,Ntitle from [News] Order By NID ASC ");
        while (dr.Read())
        {
            s++;
            str += "<tr>" +
                "<td class=\"lpage\"><a href=\"http://www.fuhepo.cn/" + dr["Htmlurl"].ToString() + "\" title=\"" + dr["Ntitle"].ToString() + "\">" + dr["Ntitle"].ToString() + "</a></td>" +
                "</tr>";
        }
        dr.Close();
        return str;
    }

}